package com.hk.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hk.mapper.DictTypeMapper;
import com.hk.model.pojo.SysDictType;
import com.hk.result.PageResult;
import com.hk.service.DictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;

@Service
public class DictTypeServiceImpl extends ServiceImpl<DictTypeMapper,SysDictType> implements DictTypeService {
    @Autowired
    private DictTypeMapper dictTypeMapper;

    /**
     * 分页条件查询字典类型
     */
    @Override
    public PageResult selectDictTypeByPage(Integer pageNum, Integer pageSize, String dictName, String dictType, Integer status, String beginTime, String endTime) {
        if (pageNum != null && pageSize != null){
            PageHelper.startPage(pageNum, pageSize);
        }

        Page<SysDictType> page = dictTypeMapper.selectDictTypeByPage(dictName, dictType, status, beginTime, endTime);
        for (SysDictType sysDictType : page) {
            sysDictType.setDictId(sysDictType.getId());
            sysDictType.setId(null);
        }
        return new PageResult(page.getTotal(), page.getResult());
    }



    /**
     * 新增字典类型
     *
     * @param sysDictType
     */
    @Override
    public void addDictType(SysDictType sysDictType) {
        dictTypeMapper.insert(sysDictType);
    }

    /**
     * 根据id查询字典类型
     *
     * @param id
     * @return
     */
    @Override
    public SysDictType getDictTypeById(Long id) {
        return dictTypeMapper.selectById(id);
    }

    /**
     * 修改字典类型
     *
     * @param sysDictType
     */
    @Override
    public void updateDictType(SysDictType sysDictType) {
        dictTypeMapper.updateById(sysDictType);
    }

    /**
     * 批量删除字典类型
     *
     * @param ids
     */
    @Override
    public void deleteDictType(Long[] ids) {
        dictTypeMapper.deleteBatchIds(Arrays.asList(ids));
    }

}
